#include <cstdio>
#include <iostream>
#include <time.h>
#include <vector>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
using namespace std;
typedef unsigned int uint;
 #define _CRT_SECURE_NO_WARNINGS
struct Edge
{
    uint v, w;
    Edge(uint _v = 0, uint _w = 0) : v(_v), w(_w){};
};
// #define sizes 4294967294 ;
vector<vector<Edge>> e;
vector<vector<uint>> cycles;
vector<bool> blocked;
vector<vector<uint>> B;
vector<uint> sstack;
vector<vector<uint>> temp;
map<unsigned int, unsigned int> ntv,vtn;
unordered_map<uint,uint> ntvv,vtnn;
uint cnt = 0;
void addEdge(uint u, uint v, uint w, uint i)
{
    if (i >= e.size())
        e.resize(i);
    e[u].push_back(Edge(v, w));
    return;
}
void unblock(uint u)
{
    blocked[u] = false;
    while (!B[u].empty())
    {
        int w = B[u][0];
        B[u].erase(B[u].begin() + 0);
        if (blocked[w])
        {
            unblock(w);
        }
    }
}
bool circuit(uint v, uint s)
{
    bool f = false;
    sstack.push_back(v);
    blocked[v] = true;
    for (int i = 0; i < e[v].size(); i++)
    {
        if (ntvv[e[v][i].v] == ntvv[s])
        {
            cycles.resize(cycles.size()+1);
            for (int j = 0; j < sstack.size(); j++)
                cycles[cnt].push_back(sstack[j]);
            cnt++;
            f = true;
        }
        else if (ntvv[e[v][i].v] > ntvv[s] && !blocked[e[v][i].v])
        {
            if (circuit(e[v][i].v, s))
                f = true;
        }
    }
    if (f)
        unblock(v);
    else
    {
        for (int i = 0; i < e[v].size(); i++)
        {
            if (find(B[e[v][i].v].begin(), B[e[v][i].v].end(), v) == B[e[v][i].v].end())
            {
                B[e[v][i].v].push_back(v);
            }
        }
    }
    sstack.pop_back();
    return f;
}
int main()
{
    freopen("test_data.txt", "r", stdin);
    //freopen("result.txt", "w", stdout);
    uint u, v, w;
    clock_t t = clock();
    uint MIN = 0x7ffff;
    uint MAX = 0;
    /*while (scanf("%d,%d,%d", &u, &v, &w) != EOF)
    {
        addEdge(u, v, w, u + 1);
        MIN = min(MIN, u);
        MIN = min(MIN, v);
        MAX = max(MAX, u);
        MAX = max(MAX, v);
    }*/
    uint num = 0;
    // while (scanf("%d,%d,%d", &u, &v, &w) != EOF)
    // {
    //     MIN = min(MIN, u);
    //     MIN = min(MIN, v);
    //     MAX = max(MAX, u);
    //     MAX = max(MAX, v);
    //     uint u_tmp, v_tmp;
    //     if (!vtn.count(u))
    //     {
    //         ntv.insert(pair<unsigned int, unsigned int>(num, u));
    //         vtn.insert(pair<unsigned int, unsigned int>(u, num));
    //         u_tmp = num;
    //         num++;
    //     }
    //     else
    //     {
    //         u_tmp = vtn[u];
    //     }
    //     if (!vtn.count(v))
    //     {
    //         ntv.insert(pair<uint, uint>(num, v));
    //         vtn.insert(pair<uint, uint>(v, num));
    //         v_tmp = num;
    //         num++;
    //     }
    //     else
    //     {
    //         v_tmp = vtn[v];
    //     }
    //     addEdge(u_tmp, v_tmp, w, u_tmp + 2);
    // }
    while (scanf("%d,%d,%d", &u, &v, &w) != EOF)
    {
        MIN = min(MIN, u);
        MIN = min(MIN, v);
        MAX = max(MAX, u);
        MAX = max(MAX, v);
        uint u_tmp, v_tmp;
        if (!vtnn.count(u))
        {
            ntvv.insert(pair<unsigned int, unsigned int>(num, u));
            vtnn.insert(pair<unsigned int, unsigned int>(u, num));
            u_tmp = num;
            num++;
        }
        else
        {
            u_tmp = vtnn[u];
        }
        if (!vtnn.count(v))
        {
            ntvv.insert(pair<uint, uint>(num, v));
            vtnn.insert(pair<uint, uint>(v, num));
            v_tmp = num;
            num++;
        }
        else
        {
            v_tmp = vtnn[v];
        }
        addEdge(u_tmp, v_tmp, w, u_tmp + 2);
    }
    //uint s = ntv[MIN];
    uint s=MIN;
    if (blocked.size() == 0)
        blocked.resize(e.size()+2);
    if (B.size() == 0)
        B.resize(e.size()+2);
    while (s<MAX)
    {
        for (uint i = s; i <= MAX; i++)
        {
            if (vtnn.count(i))
            {
                blocked[vtnn[i]] = false;
                B[vtnn[i]].clear();
            }
        }
        circuit(vtnn[s], vtnn[s]);
        s++;
    }
    //  sort(cycles.begin(), cycles.end());
    int ans = 0;
    int limites[] = {3, 4, 5, 6, 7};

    for (int i = 0; i < cycles.size(); i++)
    {
        if (cycles[i].size() >= 3 && cycles[i].size() <= 7)
        {
            ans++;
        }
    }
    // cout << ans << endl;
    printf("%d\n",ans);
    //for (int k = 0; k < 5; k++)
    //{
    //    for (int i = 0; i < cycles.size(); i++)
    //    {
    //        if (cycles[i].size() == limites[k])
    //        {
    //            for (int j = 0; j < cycles[i].size(); j++)
    //            {
    //                if (j == cycles[i].size() - 1)
    //                {
    //                    // cout << cycles[i][j];
    //                    printf("%d",ntvv[cycles[i][j]]);
    //                }
    //                else
    //                {
    //                    // cout << cycles[i][j] << ",";
    //                    printf("%d,",ntvv[cycles[i][j]]);
    //                }
    //            }
    //            // cout << endl;
    //            printf("\n");
    //        }
    //    }
    //}
    // cout<<e[1551][0].v<<endl;
    clock_t t1 = clock();
    cout<<(t1-t)*1000/CLOCKS_PER_SEC<<"ms"<<endl;
    fclose(stdin);
    //fclose(stdout);
    return 0;
}